package org.vacoor.nothing.security.nls;

import com.google.common.collect.Maps;
import org.vacoor.nothing.security.nls.support.*;

import java.util.Collections;
import java.util.Map;

/**
 */
public class TranslatorRegistry {
    public static final String NONE = "";
    public static final String GOOGLE = "google";
    public static final String BING = "bing";
    public static final String BAIDU = "baidu";
    public static final String YOUDAO = "youdao";

    private Map<String, Translator> translatorMap = Maps.newLinkedHashMap();

    public TranslatorRegistry() {
        register(GOOGLE, GoogleTickleTranslator.INSTANCE);
        register(BING, BingTranslator.INSTANCE);
        register(BAIDU, BaiduTranslator.INSTANCE);
        register(YOUDAO, YouDaoTranslator.INSTANCE);
        register("youdao2", YouDaoTickleTranslator.INSTANCE);
    }

    public Map<String, Translator> availableTranslators() {
        return Collections.unmodifiableMap(translatorMap);
    }

    public void register(String name, Translator translator) {
        translatorMap.put(name, translator);
    }

    public Translator getTranslator(String name) {
        name = null != name ? name : NONE;
        return translatorMap.get(name);
    }
}
